package com.example.sunmiv1.views;

import android.graphics.Rect;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;


public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int spanCount; //列數
    private int spacing; //間隔
    private boolean includeEdge; //是否包含邊緣

    public SpacesItemDecoration(int spanCount, int spacing, boolean includeEdge) {
        this.spanCount = spanCount;
        this.spacing = spacing;
        this.includeEdge = includeEdge;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        //這裏是關鍵，需要根據你有幾列來判斷
        int position = parent.getChildAdapterPosition(view); // item position
        if (position >= spanCount) {
            outRect.top = spacing; // item top
        }
    }
}
